{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# while循环\n",
    "- 一个循环语句\n",
    "- 表示当某条件成立的时候，就循环\n",
    "- 不知道具体循环次数，但是能确定循环的成立条件\n",
    "- while 语法：\n",
    "            while 条件表达式：\n",
    "                语句块\n",
    "         2：\n",
    "             while 条件表达式：\n",
    "                 语句块1\n",
    "             else:\n",
    "                 语句块2                 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1年的钱是106700.0\n",
      "2年的钱是113848.9\n",
      "3年的钱是121476.77629999998\n",
      "4年的钱是129615.72031209998\n",
      "5年的钱是138299.97357301068\n",
      "6年的钱是147566.07180240238\n",
      "7年的钱是157452.99861316333\n",
      "8年的钱是168002.34952024528\n",
      "9年的钱是179258.5069381017\n",
      "10年的钱是191268.8269029545\n",
      "11年的钱是204083.83830545243\n",
      "结束了\n"
     ]
    }
   ],
   "source": [
    "# 如果\n",
    "benqian = 100000\n",
    "year = 0\n",
    "while benqian < 200000:\n",
    "    benqian = benqian*(1+0.067)\n",
    "    year +=1\n",
    "    print(\"{0}年的钱是{1}\".format(year,benqian))\n",
    "else:\n",
    "    print('结束了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "结束了\n"
     ]
    }
   ],
   "source": [
    "benqian = 100000\n",
    "year = 0\n",
    "while benqian < 20000:\n",
    "    benqian = benqian*(1+0.067)\n",
    "    year +=1\n",
    "    print(\"{0}年的钱是{1}\".format(year,benqian))\n",
    "else:\n",
    "    print('结束了')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 函数\n",
    "- 函数名： \n",
    "- 函数内所有代码缩进注意"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "first line\n",
      "这个是函数里面的\n",
      "second line\n"
     ]
    }
   ],
   "source": [
    "def func():\n",
    "    print('first line')\n",
    "    print('这个是函数里面的')\n",
    "    print('second line')\n",
    "# 函数的调用： 直接函数名后面跟括号\n",
    "func()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 函数的参数和返回值\n",
    "- 参数： 负责给函数传递一些必要的数据或者信息\n",
    "- 返回值： 函数的执行结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello, zhangsan\n"
     ]
    }
   ],
   "source": [
    "# 参数\n",
    "def fun1(name):\n",
    "    print('hello, {}'.format(name))\n",
    "\n",
    "fun1('zhangsan')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
